.Orig x3000
INIT_CODE
LEA R6, #-1
ADD R5, R6, #0
ADD R6, R6, R6
ADD R6, R6, R6
ADD R6, R6, R5
ADD R6, R6, #-1
ADD R5, R5, R5
ADD R5, R6, #0
LD R4, GLOBAL_DATA_POINTER
LD R7, GLOBAL_MAIN_POINTER
jsrr R7
HALT

GLOBAL_DATA_POINTER .FILL GLOBAL_DATA_START
GLOBAL_MAIN_POINTER .FILL main
;;;;;;;;;;;;;;;;;;;;;;;;;;;;read_int;;;;;;;;;;;;;;;;;;;;;;;;;;;;
lc3_read_int
ADD R6, R6, #-2
STR R7, R6, #0
ADD R6, R6, #-1
STR R5, R6, #0
ADD R5, R6, #-1

ADD R6, R6, #-3
ADD R7, R4, #15
ADD R7, R7, #15
ADD R7, R7, #15
ADD R7, R7, #15
ADD R7, R7, #15
ADD R7, R7, #15
ADD R7, R7, #15
ADD R7, R7, #15
ADD R7, R7, #15
ADD R7, R7, #15
ADD R7, R7, #14
ldr R7, R7, #0
str R7, R5, #-1
ADD R0, R4, #15
ADD R0, R0, #7
LDR R0, R0, #0
jsrr R0
LDR R7, R6, #0
ADD R6, R6, #1
str R7, R5, #0
ldr R7, R5, #0
ADD R3, R4, #15
ADD R3, R3, #15
ADD R3, R3, #15
ADD R3, R3, #15
ADD R3, R3, #15
ADD R3, R3, #15
ADD R3, R3, #15
ADD R3, R3, #15
ADD R3, R3, #15
ADD R3, R3, #15
ADD R3, R3, #14
ldr R3, R3, #0
NOT R7, R7
ADD R7, R7, #1
ADD R7, R7, R3
BRp L15
ADD R7, R4, #3
LDR R7, R7, #0
jmp R7
L15
ADD R7, R4, #15
ADD R7, R7, #15
ADD R7, R7, #15
ADD R7, R7, #15
ADD R7, R7, #15
ADD R7, R7, #15
ADD R7, R7, #15
ADD R7, R7, #15
ADD R7, R7, #15
ADD R7, R7, #15
ADD R7, R7, #12
ldr R7, R7, #0
ADD R0, R4, #5
LDR R0, R0, #0
JMP R0
lc3_L6_rainfall
ldr R7, R5, #0
str R7, R5, #-2
ADD R3, R4, #15
ADD R3, R3, #15
ADD R3, R3, #15
ADD R3, R3, #15
ADD R3, R3, #15
ADD R3, R3, #15
ADD R3, R3, #15
ADD R3, R3, #15
ADD R3, R3, #15
ADD R3, R3, #15
ADD R3, R3, #11
ldr R3, R3, #0
NOT R7, R7
ADD R7, R7, #1
ADD R7, R7, R3
BRnz L16
ADD R7, R4, #2
LDR R7, R7, #0
jmp R7
L16
ADD R7, R4, #15
ADD R7, R7, #15
ADD R7, R7, #15
ADD R7, R7, #15
ADD R7, R7, #15
ADD R7, R7, #15
ADD R7, R7, #15
ADD R7, R7, #15
ADD R7, R7, #15
ADD R7, R7, #15
ADD R7, R7, #10
ldr R7, R7, #0
ldr R3, R5, #-2
NOT R7, R7
ADD R7, R7, #1
ADD R7, R7, R3
BRnz L17
ADD R7, R4, #2
LDR R7, R7, #0
jmp R7
L17
ADD R7, R4, #15
ADD R7, R7, #15
ADD R7, R7, #15
ADD R7, R7, #15
ADD R7, R7, #15
ADD R7, R7, #15
ADD R7, R7, #15
ADD R7, R7, #15
ADD R7, R7, #15
ADD R7, R7, #15
ADD R7, R7, #9
ldr R7, R7, #0
ldr R3, R5, #-1
ADD R6, R6, #-1
STR R0, R6, #0
ADD R6, R6, #-1
STR R3, R6, #0
AND R0, R0, #0
ADD R3, R3, #0
BRz L19
BRp L18
NOT R3, R3
ADD R3, R3, #1
L18
ADD R0, R0, R7
ADD R3, R3, #-1
BRnp L18
L19
LDR R3, R6, #0
ADD R6, R6, #1
ADD R3, R3, #0
BRzp L20
NOT R0, R0
ADD R0, R0, #1
L20
;bef epilogue x=0 y=7 z=3
ADD R7, R0, #0
LDR R0, R6, #0
ADD R6, R6, #1
;aft epilogue x=0 y=7 z=3
ldr R3, R5, #0
ADD R2, R4, #15
ADD R2, R2, #15
ADD R2, R2, #15
ADD R2, R2, #15
ADD R2, R2, #15
ADD R2, R2, #15
ADD R2, R2, #15
ADD R2, R2, #15
ADD R2, R2, #15
ADD R2, R2, #15
ADD R2, R2, #11
ldr R2, R2, #0
ADD R6, R6, #-1
STR R0, R6, #0
ADD R6, R6, #-1
STR R2, R6, #0
NOT R2, R2
ADD R2, R2, #1
ADD R0, R3, R2
LDR R2, R6, #0
ADD R6, R6, #1
ADD R3, R0, #0
LDR R0, R6, #0
ADD R6, R6, #1
add R7, R7, R3
str R7, R5, #-1
lc3_L9_rainfall
ADD R0, R4, #15
ADD R0, R0, #7
LDR R0, R0, #0
jsrr R0
LDR R7, R6, #0
ADD R6, R6, #1
str R7, R5, #0
lc3_L7_rainfall
ldr R7, R5, #0
str R7, R5, #-2
ADD R3, R4, #15
ADD R3, R3, #15
ADD R3, R3, #15
ADD R3, R3, #15
ADD R3, R3, #15
ADD R3, R3, #15
ADD R3, R3, #15
ADD R3, R3, #15
ADD R3, R3, #15
ADD R3, R3, #15
ADD R3, R3, #14
ldr R3, R3, #0
NOT R7, R7
ADD R7, R7, #1
ADD R7, R7, R3
BRn L21
ADD R7, R4, #4
LDR R7, R7, #0
jmp R7
L21
ADD R7, R4, #15
ADD R7, R7, #15
ADD R7, R7, #15
ADD R7, R7, #15
ADD R7, R7, #15
ADD R7, R7, #15
ADD R7, R7, #15
ADD R7, R7, #15
ADD R7, R7, #15
ADD R7, R7, #15
ADD R7, R7, #9
ldr R7, R7, #0
ldr R3, R5, #-2
NOT R7, R7
ADD R7, R7, #1
ADD R7, R7, R3
BRz L22
ADD R7, R4, #1
LDR R7, R7, #0
jmp R7
L22
lc3_L14_rainfall
ldr R7, R5, #-1
lc3_L1_rainfall
STR R7, R5, #3
ADD R6, R5, #1
LDR R5, R6, #0
ADD R6, R6, #1
LDR R7, R6, #0
ADD R6, R6, #1
RET



;;;;;;;;;;;;;;;;;;;;;;;;;;;;read_array;;;;;;;;;;;;;;;;;;;;;;;;;;;;
lc3_read_array
ADD R6, R6, #-2
STR R7, R6, #0
ADD R6, R6, #-1
STR R5, R6, #0
ADD R5, R6, #-1

ADD R6, R6, #-2
ADD R7, R4, #15
ADD R7, R7, #15
ADD R7, R7, #15
ADD R7, R7, #15
ADD R7, R7, #15
ADD R7, R7, #15
ADD R7, R7, #15
ADD R7, R7, #15
ADD R7, R7, #15
ADD R7, R7, #15
ADD R7, R7, #14
ldr R7, R7, #0
str R7, R5, #-1
ADD R7, R4, #15
ADD R7, R7, #15
ADD R7, R7, #15
ADD R7, R7, #15
ADD R7, R7, #15
ADD R7, R7, #15
ADD R7, R7, #4
ADD R6, R6, #-1
STR R7, R6, #0
ADD R0, R4, #15
ADD R0, R0, #6
LDR R0, R0, #0
jsrr R0
LDR R7, R6, #0
ADD R6, R6, #1
ADD R0, R4, #8
LDR R0, R0, #0
JMP R0
lc3_L25_rainfall
ldr R7, R5, #-1
ADD R3, R4, #15
ADD R3, R3, #15
ADD R3, R3, #15
ADD R3, R3, #15
ADD R3, R3, #15
ADD R3, R3, #15
ADD R3, R3, #15
ADD R3, R3, #15
ADD R3, R3, #15
ADD R3, R3, #15
ADD R3, R3, #13
ldr R3, R3, #0
add R3, R7, R3
str R3, R5, #-1
ldr R3, R5, #4
add R7, R7, R3
ldr R3, R5, #0
str R3, R7, #0
lc3_L26_rainfall
ADD R0, R4, #0
LDR R0, R0, #0
jsrr R0
LDR R7, R6, #0
ADD R6, R6, #1
str R7, R5, #0
ADD R3, R4, #15
ADD R3, R3, #15
ADD R3, R3, #15
ADD R3, R3, #15
ADD R3, R3, #15
ADD R3, R3, #15
ADD R3, R3, #15
ADD R3, R3, #15
ADD R3, R3, #15
ADD R3, R3, #15
ADD R3, R3, #12
ldr R3, R3, #0
NOT R7, R7
ADD R7, R7, #1
ADD R7, R7, R3
BRz L29
ADD R7, R4, #7
LDR R7, R7, #0
jmp R7
L29
ldr R7, R5, #-1
lc3_L23_rainfall
STR R7, R5, #3
ADD R6, R5, #1
LDR R5, R6, #0
ADD R6, R6, #1
LDR R7, R6, #0
ADD R6, R6, #1
RET

;;;;;;;;;;;;;;;;;;;;;;;;;;;;print_stats;;;;;;;;;;;;;;;;;;;;;;;;;;;;
lc3_print_stats
ADD R6, R6, #-2
STR R7, R6, #0
ADD R6, R6, #-1
STR R5, R6, #0
ADD R5, R6, #-1

ADD R6, R6, #-6
ldr R7, R5, #4
ldr R7, R7, #0
str R7, R5, #-1
ldr R7, R5, #4
ldr R7, R7, #0
str R7, R5, #-3
ldr R7, R5, #4
ldr R7, R7, #0
str R7, R5, #-2
ADD R7, R4, #15
ADD R7, R7, #15
ADD R7, R7, #15
ADD R7, R7, #15
ADD R7, R7, #15
ADD R7, R7, #15
ADD R7, R7, #15
ADD R7, R7, #15
ADD R7, R7, #15
ADD R7, R7, #15
ADD R7, R7, #13
ldr R7, R7, #0
str R7, R5, #0
ADD R0, R4, #15
ADD R0, R0, #2
LDR R0, R0, #0
JMP R0
lc3_L31_rainfall
ldr R7, R5, #-1
ldr R3, R5, #0
ldr R2, R5, #4
add R3, R3, R2
ldr R3, R3, #0
NOT R7, R7
ADD R7, R7, #1
ADD R7, R7, R3
BRp L42
ADD R7, R4, #12
LDR R7, R7, #0
jmp R7
L42
ldr R7, R5, #-1
str R7, R5, #-4
ADD R0, R4, #13
LDR R0, R0, #0
JMP R0
lc3_L36_rainfall
ldr R7, R5, #0
ldr R3, R5, #4
add R7, R7, R3
ldr R7, R7, #0
str R7, R5, #-4
lc3_L37_rainfall
ldr R7, R5, #-4
str R7, R5, #-1
ldr R7, R5, #-2
ldr R3, R5, #0
ldr R2, R5, #4
add R3, R3, R2
ldr R3, R3, #0
NOT R7, R7
ADD R7, R7, #1
ADD R7, R7, R3
BRn L43
ADD R7, R4, #14
LDR R7, R7, #0
jmp R7
L43
ldr R7, R5, #-2
str R7, R5, #-5
ADD R0, R4, #15
ADD R0, R0, #0
LDR R0, R0, #0
JMP R0
lc3_L39_rainfall
ldr R7, R5, #0
ldr R3, R5, #4
add R7, R7, R3
ldr R7, R7, #0
str R7, R5, #-5
lc3_L40_rainfall
ldr R7, R5, #-5
str R7, R5, #-2
ldr R7, R5, #-3
ldr R3, R5, #0
ldr R2, R5, #4
add R3, R3, R2
ldr R3, R3, #0
add R7, R7, R3
str R7, R5, #-3
lc3_L32_rainfall
ldr R7, R5, #0
ADD R3, R4, #15
ADD R3, R3, #15
ADD R3, R3, #15
ADD R3, R3, #15
ADD R3, R3, #15
ADD R3, R3, #15
ADD R3, R3, #15
ADD R3, R3, #15
ADD R3, R3, #15
ADD R3, R3, #15
ADD R3, R3, #13
ldr R3, R3, #0
add R7, R7, R3
str R7, R5, #0
lc3_L34_rainfall
ldr R7, R5, #0
ldr R3, R5, #5
NOT R7, R7
ADD R7, R7, #1
ADD R7, R7, R3
BRnz L44
ADD R7, R4, #11
LDR R7, R7, #0
jmp R7
L44
ldr R7, R5, #-3
ldr R3, R5, #5
ADD R6, R6, #-1
STR R0, R6, #0
ADD R3, R3, #0
BRz L45
ADD R6, R6, #-1
STR R7, R6, #0
ADD R6, R6, #-1
STR R3, R6, #0
AND R0, R0, #0
ADD R7, R7, #0
BRzp L46
NOT R7, R7
ADD R7, R7, #1
L46
ADD R3, R3, #0
BRn L47
NOT R3, R3
ADD R3, R3, #1
L47
ADD R7, R7, R3
BRn L48
ADD R0, R0, #1
BRnzp L47
L48
LDR R3, R6, #0
ADD R6, R6, #1
LDR R7, R6, #0
ADD R6, R6, #1
ADD R3, R3, #0
BRzp L49
ADD R7, R7, #0
BRzp L50
BRn L45
L49
ADD R7, R7, #0
BRzp L45
L50
NOT R0, R0
ADD R0, R0, #1
L45
ADD R7, R0, #0
LDR R0, R6, #0
ADD R6, R6, #1
;div done
ADD R6, R6, #-1
STR R7, R6, #0
ldr R7, R5, #-2
ADD R6, R6, #-1
STR R7, R6, #0
ldr R7, R5, #-1
ADD R6, R6, #-1
STR R7, R6, #0
ADD R7, R4, #15
ADD R7, R7, #15
ADD R7, R7, #15
ADD R7, R7, #15
ADD R7, R7, #6
ADD R6, R6, #-1
STR R7, R6, #0
ADD R0, R4, #15
ADD R0, R0, #6
LDR R0, R0, #0
jsrr R0
LDR R7, R6, #0
ADD R6, R6, #1
lc3_L30_rainfall
STR R7, R5, #3
ADD R6, R5, #1
LDR R5, R6, #0
ADD R6, R6, #1
LDR R7, R6, #0
ADD R6, R6, #1
RET

;;;;;;;;;;;;;;;;;;;;;;;;;;;;main;;;;;;;;;;;;;;;;;;;;;;;;;;;;
main
ADD R6, R6, #-2
STR R7, R6, #0
ADD R6, R6, #-1
STR R5, R6, #0
ADD R5, R6, #-1

ADD R6, R6, #-16
ADD R6, R6, #-16
ADD R6, R6, #-16
ADD R6, R6, #-16
ADD R6, R6, #-1
ADD R7, R5, #-16
ADD R7, R7, #-16
ADD R7, R7, #-16
ADD R7, R7, #-15
ADD R6, R6, #-1
STR R7, R6, #0
ADD R0, R4, #6
LDR R0, R0, #0
jsrr R0
LDR R7, R6, #0
ADD R6, R6, #1
;spilling -64
STR R4, R6, #-1
ADD R4, R5, #-16
ADD R4, R4, #-16
ADD R4, R4, #-16
STR R7, R4, #-16
LDR R4, R6, #-1
ADD R7, R5, #-16
ADD R7, R7, #-16
ADD R7, R7, #-16
ADD R7, R7, #-15
ADD R6, R6, #-1
STR R7, R6, #0
ADD R7, R4, #15
ADD R7, R7, #8
ADD R6, R6, #-1
STR R7, R6, #0
ADD R0, R4, #15
ADD R0, R0, #6
LDR R0, R0, #0
jsrr R0
LDR R7, R6, #0
ADD R6, R6, #1
ADD R7, R5, #-16
ADD R7, R7, #-16
ADD R7, R7, #-16
ADD R7, R7, #-16
ldr R7, R7, #0
ADD R3, R4, #15
ADD R3, R3, #15
ADD R3, R3, #15
ADD R3, R3, #15
ADD R3, R3, #15
ADD R3, R3, #15
ADD R3, R3, #15
ADD R3, R3, #15
ADD R3, R3, #15
ADD R3, R3, #15
ADD R3, R3, #14
ldr R3, R3, #0
NOT R7, R7
ADD R7, R7, #1
ADD R7, R7, R3
BRn L55
ADD R7, R4, #15
ADD R7, R7, #4
LDR R7, R7, #0
jmp R7
L55
ADD R7, R5, #-16
ADD R7, R7, #-16
ADD R7, R7, #-16
ADD R7, R7, #-16
ldr R7, R7, #0
ADD R6, R6, #-1
STR R7, R6, #0
ADD R7, R5, #-16
ADD R7, R7, #-16
ADD R7, R7, #-16
ADD R7, R7, #-15
ADD R6, R6, #-1
STR R7, R6, #0
ADD R0, R4, #10
LDR R0, R0, #0
jsrr R0
lc3_L53_rainfall
ADD R7, R4, #15
ADD R7, R7, #15
ADD R7, R7, #15
ADD R7, R7, #15
ADD R7, R7, #15
ADD R7, R7, #15
ADD R7, R7, #15
ADD R7, R7, #15
ADD R7, R7, #15
ADD R7, R7, #15
ADD R7, R7, #14
ldr R7, R7, #0
lc3_L51_rainfall
STR R7, R5, #3
ADD R6, R5, #1
LDR R5, R6, #0
ADD R6, R6, #1
LDR R7, R6, #0
ADD R6, R6, #1
RET

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;	void printf(const char *format, ...)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

PRINTF_PERCENT .FILL -37
PRINTF_C .FILL -99
PRINTF_D .FILL -100
PRINTF_S .FILL -115
PRINTF_B .FILL -98
PRINTF_O .FILL -111
PRINTF_X .FILL -120
PRINTF_ASCII .FILL 48 		;postive ascii value of '0'
.FILL 49
.FILL 50
.FILL 51
.FILL 52
.FILL 53
.FILL 54
.FILL 55
.FILL 56
.FILL 57
.FILL 65        ;A
.FILL 66
.FILL 67
.FILL 68
.FILL 69
.FILL 70
PRINTF_MINUS .FILL 45  
PRINTF_BUF .BLKW 18
 

lc3_printf
ADD R6, R6, #-2
STR R7, R6, #0		;return address
ADD R6, R6, #-1
STR R5, R6, #0
ADD R5, R6, #-1

ADD R6, R6, #-1
STR R4, R6, #0

ADD R5, R5, #4		;cheating with the bp (no longer bp)
LDR R4, R5, #0		;got addr of format string


PRINTF_LOOP	;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

LDR R0, R4, #0

ADD R0, R0, #0		;End of string? (0x0000)
BRz PRINTF_DONE

ADD R2, R0, #0
LD R1, PRINTF_PERCENT
ADD R2, R2, R1
BRnp PRINTF_CHAR		

ADD R4, R4, #1
LDR R0, R4, #0
;is it %c?
ADD R2, R0, #0
LD R3, PRINTF_C
ADD R2, R2, R3
BRnp PRINTF_CHECKSTR
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;%c
ADD R5, R5, #1
LDR R0, R5, #0

PRINTF_CHAR
OUT

ADD R4, R4, #1
BRnzp PRINTF_LOOP

PRINTF_CHECKSTR
;is it %s?
ADD R2, R0, #0
LD R7, PRINTF_S
ADD R2, R2, R7
BRnp PRINTF_CHECKDEC		

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;%s

ADD R5, R5, #1
LDR R0, R5, #0
PUTS

ADD R4, R4, #1
BRnzp PRINTF_LOOP

PRINTF_CHECKDEC
;is it %d?
ADD R2, R0, #0
LD R7, PRINTF_D
ADD R2, R2, R7
;BRnp PRINTF_ERROR
BRnp PRINTF_CHECKHEX

AND R2, R2, #0
ADD R2, R2, #-10		;going to divide by 10 by using sub loop
BRnzp PRINTF_NUM

PRINTF_CHECKHEX

ADD R2, R0, #0
LD R7, PRINTF_X
ADD R2, R2, R7
BRnp PRINTF_CHECKOCT

AND R2, R2, #0
ADD R2, R2, #-16		;going to divide by 10 by using sub loop
BRnzp PRINTF_NUM

PRINTF_CHECKOCT

ADD R2, R0, #0
LD R7, PRINTF_O
ADD R2, R2, R7
BRnp PRINTF_CHECKBIN

AND R2, R2, #0
ADD R2, R2, #-8		;going to divide by 10 by using sub loop
BRnzp PRINTF_NUM

PRINTF_CHECKBIN

ADD R2, R0, #0
LD R7, PRINTF_B
ADD R2, R2, R7
BRnp PRINTF_ERROR

AND R2, R2, #0
ADD R2, R2, #-2		;going to divide by 10 by using sub loop
;BRnzp PRINTF_NUM



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;%d
PRINTF_NUM

LEA R7, PRINTF_BUF
ADD R7, R7, #15 
ADD R7, R7, #1 

;AND R2, R2, #0
;ADD R2, R2, #-10		;going to divide by 10 by using sub loop

ADD R5, R5, #1			;acquire the binary number
LDR R0, R5, #0

ADD R0, R0, #0
BRzp PRINTF_DECPOS 

NOT R0, R0				;make num positive for sub loop
ADD R0, R0, #1

PRINTF_DECPOS

AND R3, R3, #0
ADD R3, R3, #-1

PRINTF_DIVLOOP
ADD R3, R3, #1			;num/10 
ADD R0, R0, R2			;R0 = num % 10 - 10
BRzp PRINTF_DIVLOOP

ADD R3, R3, #0
BRz PRINTF_LASTDIGIT

;LD R1, PRINTF_ASCII
;ADD R1, R1, R0
;NOT R2, R2
;ADD R1, R1, R2 
;ADD R1, R1, #1
;NOT R2, R2
;;;;;ADD R1, R1, #10
;STR R1, R7, #0
;ADD R7, R7, #-1			;stored ascii value of one digit

LEA R1, PRINTF_ASCII
ADD R1, R1, R0
NOT R2, R2
ADD R1, R1, R2 
ADD R1, R1, #1
NOT R2, R2
LDR R1, R1, #0
STR R1, R7, #0
ADD R7, R7, #-1			;stored ascii value of one digit

ADD R0, R3, #0			;num/10

BRnzp PRINTF_DECPOS

PRINTF_LASTDIGIT

;LD R1, PRINTF_ASCII
;ADD R1, R1, R0
;ADD R1, R1, #10
;STR R1, R7, #0

LEA R1, PRINTF_ASCII
ADD R1, R1, R0
NOT R2, R2
ADD R1, R1, R2 
ADD R1, R1, #1
NOT R2, R2
LDR R1, R1, #0
STR R1, R7, #0			;stored ascii value of highest order digit

LDR R0, R5, #0
ADD R0, R0, #0
BRzp PRINTF_DECSTRING

LD R0, PRINTF_MINUS		;num was negative
ADD R7, R7, #-1
STR R0, R7, #0			;stored ascii value negative sign

PRINTF_DECSTRING		;print the calculated string
ADD R0, R7, #0
PUTS

ADD R4, R4, #1
BRnzp PRINTF_LOOP

PRINTF_ERROR
PRINTF_DONE

LDR R4, R6, #0		;restore R4
ADD R6, R6, #1

LDR R5, R6, #0		;restore bp
ADD R6, R6, #1

LDR R7, R6, #0		;restore ret addr
ADD R6, R6, #1

RET
; char getchar(void)

lc3_getchar

STR R7, R6, #-3
STR R0, R6, #-2
GETC
OUT
STR R0, R6, #-1
LDR R0, R6, #-2
LDR R7, R6, #-3
ADD R6, R6, #-1
RET

GLOBAL_DATA_START
read_int .FILL lc3_read_int
L6_rainfall .FILL lc3_L6_rainfall
L9_rainfall .FILL lc3_L9_rainfall
L7_rainfall .FILL lc3_L7_rainfall
L14_rainfall .FILL lc3_L14_rainfall
L1_rainfall .FILL lc3_L1_rainfall
read_array .FILL lc3_read_array
L25_rainfall .FILL lc3_L25_rainfall
L26_rainfall .FILL lc3_L26_rainfall
L23_rainfall .FILL lc3_L23_rainfall
print_stats .FILL lc3_print_stats
L31_rainfall .FILL lc3_L31_rainfall
L36_rainfall .FILL lc3_L36_rainfall
L37_rainfall .FILL lc3_L37_rainfall
L39_rainfall .FILL lc3_L39_rainfall
L40_rainfall .FILL lc3_L40_rainfall
L32_rainfall .FILL lc3_L32_rainfall
L34_rainfall .FILL lc3_L34_rainfall
L30_rainfall .FILL lc3_L30_rainfall
L53_rainfall .FILL lc3_L53_rainfall
L51_rainfall .FILL lc3_L51_rainfall
printf .FILL lc3_printf
getchar .FILL lc3_getchar
L52_rainfall .STRINGZ "The array is located at memory address %d\n"
L41_rainfall .STRINGZ "Min = %d\nMax = %d\nAvg = %d\n"
L24_rainfall .STRINGZ "Enter rainfall numbers.  Enter 32767 for me to average them up!\n"
L13_rainfall .FILL #10
L12_rainfall .FILL #57
L11_rainfall .FILL #48
L5_rainfall .FILL #32767
L28_rainfall .FILL #1
L2_rainfall .FILL #0
.END
